package edu.dayu.sort;

import java.util.Arrays;

/**
 * @author: dayu
 * @date: 2023/6/22 21:39
 * 归并排序
 *
 */
public class MergeSort {
    public static void main(String[] args) {
        int[] arr = {6,4,5,7,2,8,3,0,9,1};
        sort(arr,0, arr.length-1);
    }

    public static void sort(int[] arr,int low,int high){
        if (low>=high){
            return;
        }
        sort(arr,low,(low+high)/2);
        sort(arr,(low+high)/2+1,high);
        for (int i = low; i < high; i++) {
            for (int j = low; j <high-i+low ; j++) {
                if (arr[j]>arr[j+1]){
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                 }
            }
        }
        System.out.println(Arrays.toString(arr));
    }
}
